﻿@model IEnumerable<TestSystem.Domain.Entities.Authorisation.User>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_adminLayout.cshtml";
}

<script type="text/javascript">
    $(function () {
        $(".RemoveLink").click(function () {
            var recordToDelete = $(this).attr("data-id");
            if (recordToDelete != '') {
                $.post("/Account/Remove", { "id": recordToDelete },
                    function (data) {
                            $('#row-' + data.DeleteId).fadeOut('slow');
                            $('#update-message').text(data.Message);
                            if(data.ItemCount == 0)
                                $('#usersTable').fadeOut('slow');
                                
                    });
            }
        });
    });
</script>

<h2>Zarządzaj użytkownikami</h2>

<table class="striped" id="usersTable">
    <thead>
        <tr>
            <th>Nazwa</th>
            <th>Rola</th>
            <th>Ostatnie logowanie</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr id="row-@item.UserId">
                <td>
                    @item.Username
                </td>
                <td>
                    @foreach(var role in item.Roles)
                    {
                        <p>
                            @role.RoleName
                        </p>   
                    }
                </td>
                 <td>
                    @item.LastActivityDate
                </td>
                <td>
                    Edycja / 
                    <a href="#" class="RemoveLink"data-id="@item.UserId">Usuń</a>
                </td>
            </tr>
        }
    </tbody>
</table>
